package com.lpf.memento;

// 测试备忘录模式
public class MementoPatternDemo {
    public static void main(String[] args) {
        Originator originator = new Originator();
        Caretaker caretaker = new Caretaker();

        // 设置状态并保存到备忘录
        originator.setState("State #1");
        caretaker.add(originator.saveStateToMemento());

        originator.setState("State #2");
        caretaker.add(originator.saveStateToMemento());

        originator.setState("State #3");
        System.out.println("Current State: " + originator.getState());

        // 恢复到之前的状态
        originator.getStateFromMemento(caretaker.get(0));
        System.out.println("Restored State: " + originator.getState());
    }
}